package main.java.org.dss.lm.admin.controller.admin;

import java.util.ArrayList;
import java.util.List;

import main.java.org.dss.lm.admin.bean.UserBean;
import main.java.org.dss.lm.admin.common.ITSConstants;
import main.java.org.dss.lm.admin.dao.admin.IUserService;
import main.java.org.dss.lm.admin.dao.admin.UserService;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserAction extends ActionSupport  implements ModelDriven<UserBean>, ITSConstants
{
    private UserBean userBean = new UserBean();

    private IUserService userService = new UserService();
    
    /**
     * This method is an overridden method of ModelDriven class which returns login entity object,
     * populated with the login form.
     *
     * @return the AccountEntity object.
     */
    @Override
    public UserBean getModel()
    {
        return userBean;
    }

    /**
     * This method checks authentication of the user.
     *
     * @return a String indicating successful login or failure.
     */
    public String addUser()
    {
    	try {
    		System.out.println("gets"+getModel().getSelectedGroups());
    		
    		userService.addUser(getModel());
        } catch (Exception exp) {            
        }

        return ITSConstants.SUCCESS;
    }
    
    public String updateUser()
    {
    	try {    		
    		userService.updateUser(getModel());
        } catch (Exception exp) {            
        }

        return ITSConstants.SUCCESS;
    }
    
    /*public List<UserBean> getUsersInDatabase() {
		return usersInDatabase;
	}

	public void setUsersInDatabase(List<UserBean> usersInDatabase) {
		this.usersInDatabase = usersInDatabase;
	}
	
	private String editUserDetails;
    public String getEditUserDetails() {
        return editUserDetails;
    }
    public void setEditUserDetails(String editUserDetails) {
        this.editUserDetails = editUserDetails;
    }

    private String deleteUserDetails;
    public String getDeleteUserDetails() {
        return deleteUserDetails;
    }
    public void setDeleteUserDetails(String deleteUserDetails) {
        this.deleteUserDetails = deleteUserDetails;
    }*/        
    
} // End Class LoginAction
